Repository navigation
Expose MeshGL.merged() to recompute lost merge vectors - #3
Merged
Merged
Conversation
Wraps the existing C++ MeshGL::Merge() helper, which is otherwise unreachable from Swift. Manifoldness is judged by shared vertex indices, not position, so a surface that is closed geometrically but carries split coincident vertices (e.g. after an STL round-trip that drops the merge vectors) is reported non-manifold and `Manifold(_:)` throws. `merged()` snaps those vertices back together so the mesh is accepted. Adds two tests: a split tetrahedron that is rejected before merged() and accepted (with correct volume) after, and a no-op check on an already connected cube.
Owner
|
This looks great and makes sense. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Exposes a Swift
MeshGL.merged()that wraps the existing C++MeshGL::Merge(). That helper is currently unreachable from the Swift API —MeshGLis constructed but itsMerge()is never surfaced, andManifold.init(_:)doesn't merge.Why
Manifold judges manifoldness by shared vertex indices, not position. A surface that is closed geometrically but carries split/unmerged coincident vertices therefore reports a non-manifold status, and
try Manifold(meshGL)throws — even though the geometry is watertight.This is exactly the case the C++
Merge()doc comment calls out: "the case where a manifold MeshGL was produced, but its merge vectors were lost due to a round-trip through a file format." It's the common situation when ingesting STL (and other formats that don't carry merge vectors): every triangle brings its own copies of shared corners. Today there's no way to recover from Swift without dropping to the C bindings.merged()returns a copy with the merge vectors recomputed, so the mesh is accepted:API
Non-mutating (returns a copy), matching the immutable
MeshGLvalue type. If you'd prefer a different shape — a mutating@discardableResult func merge() -> Boolmirroring the C++ return, or auto-merging insideManifold.init(_:)— happy to adjust. I went with the least-invasive option that doesn't change existing construction behaviour.Tests
Manifold(_:)beforemerged()and accepted after, with the correct volume (1/6).merged()on an already-connected cube is a no-op (volume preserved).Full suite green locally (81 tests, macOS).
Context
Found while consuming manifold-swift from a mesh-reconstruction pipeline (ref #2).
slice/trim/projection/properties all had Swift equivalents —Merge()was the only piece we still needed the raw C API for.